COSC 220 Computer Science II
STL vector
This lab will give you some practical experience with vector APIs.
The function prints out all elements in a vector to cout.
template<typename T>
void writeVector(const vector<T>&vect);
The function performs a sequential search on a vector within range [first, last).
template<typenameT>
int seqVectSearch(const vector<T>&vect, int first, int last, const T&target);
The function removes all the duplicate entries from
vect.
template<typenameT>
void removeDup(vector<T>&vect);
Tasks (Important Do these tasks in the order given.)
- Copy
vectorAux.cpp to your own directory. Just
copy the file, don't write any code right now.
vectorAux.cpp contains
the following definitions:
- writeVector(const vector<T>& v) that writes vector
v to cout.
- seqVectSearch(...) that performs a sequential search in a vector.
- removeDup(vector<T>& v) that removes duplicates from
v using seqSearchVect.
- Copy vectorDriver.cpp to your own directory. Use
this file as-is. No changes are needed.
- Based on the definitions and descriptions in
vectorAux.cpp, write the
appropriate header file vectorAux.h. This file must be guarded. Since
template code is involved, #include "vectorAux.cpp" at the bottom of
the header file. Be sure to document each function in the header file.
- Use g++ to compile and link
vectorDriver.cpp. You should get no
compilation or linking errors. If you do, fix the problem. Note that the
output will not be correct if you run the program because some functions have
not yet been implemented.
- Write seqSearchVect for vectors. Recompile
vectorDriver.cpp to check for
errors.
- Write removeDup. Compile, link, and run
vectorDriver.cpp. Fix any errors. Your program should now be working for
the removeDup function.
WHAT TO SUBMIT TO YOUR INSTRUCTOR:
-
1. All the required output you are asked to write down in the
above tasks.
-
2. Answers to all the questions from the above tasks and output
of your program.
-
3. Upload all your source code to my class, put output of your
programs, answer to all the questions in a pdf file and upload
it to myClass as well.